package com.naiterui.common.jinshuju.util;

import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;

@SuppressWarnings("unused")
public final class SpringContextUtil {

    /**
     * spring容器
     */
    private static ApplicationContext context;

    public static <T> T getBean(String beanName, Class<T> clazz) {
        Assert.notNull(context, "ApplicationContext not be null");
        return context.getBean(beanName, clazz);
    }

    public static <T> T getBean(Class<T> clazz) {
        Assert.notNull(context, "ApplicationContext not be null");
        return context.getBean(clazz);
    }

    public static void init(ApplicationContext context) {
        SpringContextUtil.context = context;
    }


}
